package com.vca.admin.controller;


import com.vca.common.request.VcaAboutAddOrUpdateRequest;
import com.vca.common.request.VcaAboutAdminRequest;
import com.vca.common.response.AboutAdminResponse;
import com.vca.common.response.VcaAboutAdminResponse;
import com.vca.common.result.CommonResult;
import com.vca.service.service.VcaAboutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关于我们控制器
 *
 * @author Li
 * @date 2022/11/28   11:22
 */
@Slf4j
@RestController("VcaAboutController")
@RequestMapping("api/admin/about")
@Api(tags = "关于我们控制器")
public class VcaAboutController {

    @Autowired
    private VcaAboutService vcaAboutService;

    /**
     * 关于我们列表
     *
     * @return
     * @author Li
     * @date 2022/11/28 11:29
     */
    @PreAuthorize("hasAuthority('admin:about:list')")
    @ApiOperation("展览管理")
    @GetMapping("/list")
    public CommonResult<List<VcaAboutAdminResponse>> getList(@ModelAttribute @Validated VcaAboutAdminRequest request) {
        return CommonResult.success(vcaAboutService.getList(request));
    }

    /**
     * 修改排序
     *
     * @param aboutId
     * @param sort
     * @return
     * @author Li
     * @date 2022/11/28   13:10
     */
    @PreAuthorize("hasAuthority('admin:about:update:sort')")
    @ApiOperation("修改排序")
    @GetMapping("/updateSort")
    public CommonResult updateSort(Long aboutId, Integer sort) {
        return vcaAboutService.updateSort(aboutId, sort) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * @Description: 修改状态
     * @Param: [aboutId]
     * @author: Li
     * @date: 2022/11/28 13:44
     * @return: com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:about:update:status')")
    @ApiOperation("修改状态")
    @GetMapping("/updateStatus")
    public CommonResult updateStatus(Long aboutId) {
        return vcaAboutService.updateStatus(aboutId) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * @param request
     * @return com.vca.common.result.CommonResult
     * @description 添加关于我们
     * @author Li
     * @date 2022/11/28 13:53
     */
    @PreAuthorize("hasAuthority('admin:about:add')")
    @ApiOperation("添加关于我们")
    @PostMapping("/add")
    public CommonResult add(@RequestBody VcaAboutAddOrUpdateRequest request) {
        return vcaAboutService.addAbout(request) ? CommonResult.success() : CommonResult.failed();
    }


    /**
     * @Description: 修改关于我们
     * @Param: [request]
     * @author: Li
     * @date: 2022/11/28 13:49
     * @return: com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:about:update')")
    @ApiOperation("修改关于我们 ")
    @PostMapping("/update")
    public CommonResult update(@RequestBody VcaAboutAddOrUpdateRequest request) {
        return vcaAboutService.updateAbout(request) ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * @param aboutId
     * @return com.vca.common.result.CommonResult
     * @description 删除
     * @author Li
     * @date 2022/11/28 14:13
     */
    @PreAuthorize("hasAuthority('admin:about:delete')")
    @ApiOperation("删除")
    @GetMapping("/delete")
    public CommonResult delete(Long aboutId) {
        return vcaAboutService.deleteAbout(aboutId) ? CommonResult.success() : CommonResult.failed();
    }

    /**
    * @description 根据id查询详情
    * @param aboutId
    * @author Li
    * @date 2022/12/2 18:21
    * @return com.vca.common.result.CommonResult<com.vca.common.response.AboutAdminResponse>
    */
    @PreAuthorize("hasAuthority('admin:about:get')")
    @ApiOperation("根据id查询详情")
    @GetMapping("/get")
    public CommonResult<AboutAdminResponse> getAbout(Long aboutId) {
        return CommonResult.success(vcaAboutService.getAbout(aboutId));
    }

}
